package com.song.shop.sort;

/**
 * @author Song Yinghui
 * @date 2019/11/27
 * @Version 1.0
 */
public class QuickSort {

    public void quickSort(int[] arry, int start, int end){
        
        if (start < end){
            //获取基准值
            int index = getIndex(arry,start,end);
            quickSort(arry,0,index-1);
            quickSort(arry,index+1,end);
        }
    }

    private int getIndex(int[] arry, int start, int end) {

        //基准数据
        int tmp = arry[start];
        while (start < end){
            while (start < end && arry[end] >= tmp){
                end--;
            }
            arry[start] = arry[end];
            while (start <end && arry[start]<= tmp){
                start++;
            }
            arry[end] = arry[start];
        }

        arry[start] = tmp;
        return start;
    }

    public static void main(String[] args) {

        int[] arry = {10,7,90,28,12,34,11,12};

        QuickSort quickSort = new QuickSort();
        quickSort.quickSort(arry,0,arry.length-1);

        for (int i : arry) {
            System.out.println(i);
        }
    }
}
